#!/usr/bin/env bash

while true; do
        date '+  %a %d %b   %R ' > /tmp/CurTime.tmp
		echo "USD = $(curl -s https://www.cbr.ru/scripts/XML_daily_eng.asp | grep -oP '<CharCode>USD<\/CharCode>.*?<Value>(.*?)<\/Value>' | grep -oP '\d+,\d+|\d+.\d+' | sed 's/,/./' | awk '{printf("%.2f\n",$1)}') RUB" > /tmp/USD_Price.tmp
		
		echo "BTC = $(curl -s -X GET "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT" | jq -r '.price | tonumber | tostring |  (split(".") | .[0] + .[1][:0])')" > /tmp/Bitcoin_Price.tmp
		
        echo "MATIC = $(curl -s -X GET "https://api.binance.com/api/v3/ticker/price?symbol=MATICUSDT" | jq -r '.price | tonumber | tostring |  (split(".") | .[0] + "." + .[1][:2])')" > /tmp/Matic_Price.tmp
        
        echo "POW: $(acpi -s | cut -d' ' -f4 | sed 's/.$//')" > /tmp/Batary.tmp
		bash /home/q/Programms/wether/wether1.sh

		sleep 60s
done &


while true; do

		LOCALTIME=$(echo $(< /tmp/CurTime.tmp))

		WETHER=$(echo $(< /tmp/wether.tmp))

		MEM=$(echo $(free -h --kilo | awk '/^Mem:/ {print $3 "/" $2}'))
		CPU=$(echo "CPU: "$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]"%")

		BTC1=$(echo $(< /tmp/Bitcoin_Price.tmp))
        MATIC2=$(echo $(< /tmp/Matic_Price.tmp))
        USD1=$(echo $(< /tmp/USD_Price.tmp))

		UPL=$(echo $(ifstat -i wlo1 1s 1| awk 'NR==3 {print $1}'))
		DOW=$(echo $(ifstat -i wlo1 1s 1| awk 'NR==3 {print $2}'))

		BAT=$(echo $(< /tmp/Batary.tmp))

		BATX=$(echo $(acpi -s | cut -d' ' -f3 | sed 's/.$//'))

		WOD=$(echo "Charging")

		if [ "$BATX" = "$WOD" ]
		then	
			BATZ=$(echo "+")

		else
			BATZ=$(echo "-")

		fi
	xsetroot -name "[ $WETHER ] [ ▼ $UPL Kb/s ][ ▲ $DOW Kb/s] [ $MATIC2 USD ][ $BTC1 USD ][ $USD1 ] [ RAM: $MEM ][ $CPU ] [ $BAT$BATZ ] [ $LOCALTIME ] ☭"
    sleep 1s
done &
